package com.citycloud.ccuap.tc.admin.sec.secrole;

import com.citycloud.ccuap.commons.json.CheckedTreeNode;
import com.citycloud.ccuap.commons.sys.entity.SysRole;
import com.citycloud.ccuap.commons.sys.role.RoleService;
import com.citycloud.ccuap.tc.admin.model.SecRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by rabbitQ on 2018/8/15.
 */
@Service
public class SecRoleService implements ISecRoleService {

    /**
     * 注入cuapp原有
     */
    @Autowired
    private RoleService roleService;


    /**
     * 1、根据roleID获取(封装)Sec_Role对象
     * sysRole对象封装成Sec_Role
     */
    @Override
    public SecRole getSecRoleById(Long roleId, Long projectId, SysRole sysRole, boolean index){
        SecRole secRole = new SecRole();
        List<CheckedTreeNode> funcPermissions =  roleService.findAllFunNodeTree(roleId,projectId);
        if(index == true){
            //需要请求数据库查询sysRole对象
            SysRole originalRole = roleService.findById(roleId);
            secRole.setOriginalRole(originalRole);
        }else if(index == false){
            //将sysRole封装成secRole
            secRole.setOriginalRole(sysRole);
        }
        secRole.setFuncPermissions(funcPermissions);
        //数据权限,暂时空缺，需要刘建伟提供的接口
        secRole.setDataPermissions(null);
        return secRole;
    }

}
